﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FineSoft.Models
{
	public class NativeObject : Object
	{
		public override string ConfigsString
		{
			get
			{
				if (this.Type == Class.Date)
				{
					System.DateTime time = (System.DateTime)this.Value;
					return string.Format("new Date({0}, {1}, {2}, {3}, {4}, {5}, {6})", time.Year, time.Month - 1, time.Day, time.Hour, time.Minute, time.Second, time.Millisecond);
				}
				if (this.Type == Class.Function)
					return (string)this.Value;

				string json = Newtonsoft.Json.Linq.JObject.FromObject(new { o = this.Value }).ToString();
				json = json.TrimStart('{', '\r', '\n');
				json = json.TrimEnd('}', '\r', '\n');
				return json.Substring(json.IndexOf(':') + 1).Trim();
			}
		}

		public override string ConfigsStringInEditor
		{
			get
			{
				if (this.Type == Class.Function)
					return string.Format("new Function('{0}')", this.Value);

				return base.ConfigsStringInEditor;
			}
		}

		public object Value;
	}
}